#!/bin/csh -f
#
# This is the generic script for invoking the dbx debugger on a
# PCR world.  It normally takes no arguments, but instead 'sources'
# additional commands it needs from a file in the current directory
# called XRDBXInner.  If the environment variable XR_XRDBX_Source
# is defined it will source from there instead.  This script takes
# a single optional argument, which is the name of a core file to
# be analyzed instead of the default pid.
#
# -mdw 10/26/89

# Get additional info
if ($?XR_XRDBX_Source == 0) then
	source XRDBXInner
else
	source ${XR_XRDBX_Source}
endif

# Make sure we got what we needed from the file.
if ($?core == 0) then
	echo "Variable 'core' was not defined, aborting."
	exit 1
endif
if ($?model == 0) then
	echo "Variable 'model' was not defined, aborting."
	exit 1
endif
if ($1 != "") then
	set core = $1
endif

# Make sure the necessary environment is around, else use defaults.
if ( $?XR_HOME == 0 ) then
	setenv XR_HOME /net/palain/jaune/xrhome
endif
if ( $?XR_CONFIG == 0 ) then
	setenv XR_CONFIG Threads
endif
if ( $?XR_VERSION == 0 ) then
	setenv XR_VERSION INSTALLED
endif
if ( $?XR_MACH == 0 ) then
	setenv XR_MACH `mach`
endif
if ( $?XR_DBX == 0 ) then
	setenv XR_DBX dbx
endif

# Try for a source version
if ($?XR_SRCVERSION == 0) then
	setenv XR_SRCVERSION ${XR_HOME}/${XR_VERSION}/SRC
endif	

# Finally, down to real work.
echo Debugging with symbols from file ${model}, source in ${XR_SRCVERSION}, and state in ${core}.
cp $model $model.dbx
echo -n Transforming symtab file ... 
${XR_HOME}/${XR_VERSION}/BIN/${XR_CONFIG}-${XR_MACH}/transform_symtab $model.dbx
if ($1 != "") then
	${XR_HOME}/${XR_VERSION}/BIN/${XR_CONFIG}-${XR_MACH}/fixcore $1 $model.dbx
endif

echo done.

exec ${XR_DBX} -I. -I${XR_SRCVERSION} $model.dbx $core
